package com.ruoyi.web.controller.erpbase;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.Drivers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Goodss;
import com.ruoyi.system.service.IGoodssService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 *  商品Controller
 * 
 * @author he
 * @date 2025-08-13
 */
@Api(tags = "商品接口")
@RestController
@RequestMapping("/system/goodss")
public class GoodssController extends BaseController
{
    @Autowired
    private IGoodssService goodssService;

    /**
     * 查询 商品列表
     */
    @ApiOperation("查询商品信息")
    @PreAuthorize("@ss.hasPermi('system:goodss:list')")
    @GetMapping("/list")
    public TableDataInfo list(Goodss goodss)
    {
        startPage();
        List<Goodss> list = goodssService.selectGoodssList(goodss);
        return getDataTable(list);
    }

    /**
     * 导出 商品列表
     */
    @ApiOperation("导出商品信息")
    @PreAuthorize("@ss.hasPermi('system:goodss:export')")
    @Log(title = " 商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Goodss goodss)
    {
        List<Goodss> list = goodssService.selectGoodssList(goodss);
        ExcelUtil<Goodss> util = new ExcelUtil<Goodss>(Goodss.class);
        util.exportExcel(response, list, " 商品数据");
    }

    /**
     * 获取 商品详细信息
     */
    @ApiOperation("获取商品详细信息")
    @PreAuthorize("@ss.hasPermi('system:goodss:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(goodssService.selectGoodssById(id));
    }

    /**
     * 新增 商品
     */
    @ApiOperation("新增商品信息")
    @PreAuthorize("@ss.hasPermi('system:goodss:add')")
    @Log(title = " 商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Goodss goodss)
    {
        return toAjax(goodssService.insertGoodss(goodss));
    }

    /**
     * 修改 商品
     */
    @ApiOperation("修改商品信息")
    @PreAuthorize("@ss.hasPermi('system:goodss:edit')")
    @Log(title = " 商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Goodss goodss)
    {
        return toAjax(goodssService.updateGoodss(goodss));
    }

    /**
     * 删除 商品
     */
    @ApiOperation("删除商品信息")
    @PreAuthorize("@ss.hasPermi('system:goodss:remove')")
    @Log(title = " 商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodssService.deleteGoodssByIds(ids));
    }


    @ApiOperation("商品下拉框信息")
    @PostMapping("/getGoodsInfoList")
    public TableDataInfo getGoodsInfoList(@RequestParam(value = "paramName", required = false) String paramName)
    {
        List<Goodss> list = goodssService.getGoodsInfoList(paramName);
        return getDataTable(list);
    }
}
